package com.mpyy.handler.purchase;

import com.alibaba.fastjson.JSON;
import com.mpyy.pojo.PurchaseStockDesc;
import com.mpyy.service.purchase.SearchProBatchNumServiceInter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version 1.0
 * @Descoription SearchProBatchNumHandler
 * @Author CG
 * @date 2022-03-28
 */
@Controller
public class SearchProBatchNumHandler {
    @Autowired
    private SearchProBatchNumServiceInter proBatchNumServiceInter;

    /**查询批号信息
     *
     * @param proId
     * @param purStoDate
     * @return
     */
    @RequestMapping(value ="/searchProBatchNum/{proId}/{purStoDate}" )
    @ResponseBody
    public  String searchProBatchNum(@PathVariable String proId,@PathVariable String purStoDate ){

        PurchaseStockDesc purchaseStockDesc = proBatchNumServiceInter.searchProBatchNum(proId, purStoDate);
        String proBatchNum =proId;
        if (null!=purchaseStockDesc) {
            proBatchNum = purchaseStockDesc.getProBatchNum();
        }

        return proBatchNum;
    }

    /**查询进货历史
     *
     * @param purchaseStockDesc
     * @return
     */
   @RequestMapping(value = "/searchPurchaseHistory")
   @ResponseBody
     public String  searchPurchaseHistory(PurchaseStockDesc purchaseStockDesc){
       System.out.println(purchaseStockDesc.getProId());
       List<PurchaseStockDesc> purchaseStockDescs = proBatchNumServiceInter.searchPurchaseHistory(purchaseStockDesc);
       Map<Object,Object> map = new HashMap<>();
       map.put("code",0);
       map.put("msg","");
       map.put("count",purchaseStockDescs.size());
       map.put("data",purchaseStockDescs);
       System.out.println(JSON.toJSONString(map));
       return JSON.toJSONString(map);

  }
}
